/**
 * Created by Administrator on 2018/3/13.
 */
$(function () {
    var departId = '', departAlias, pathname = window.location.pathname;
    $("#departModal").modal({
        backdrop: false,
        show: false
    });
    $('#departLists').change(function () {
        departId = $('#departLists option:selected').attr('data-departId');
        departAlias = $('#departLists option:selected').attr('data-alias');
    });
    //渲染部门groups
    $('#departModal').on('show.bs.modal', function () {
        $.ajax({
            url: '/groups',
            data: {},
            success: function (data) {
                var str = '<option value="" data-departId="none" class="form-control">--请选择--</option>';
                for (var i = 0; i < data.length; i++) {
                    var item = data[i];
                    str += '<option class="form-control" data-departId="' + item.departId + '" data-alias="' + item.departAlias + '" data-departname="' + item.departName + '">' + item.departAlias + '</option>';
                }
                $('#departLists').html(str);
            },
            error: function (err) {
                console.log(err);
            },
            dataType: "json"
        });
    });
    //加载部门
    $('.select-depart-confirm').click(function () {
        var departName = $('#departLists option:selected').attr('data-departname');//唯一标识
        if (departId && departAlias) {
            switch (departName) {
                case 'OP'://系统运维部
                    window.location.href = '/sysmain?departId=' + departId + '&departAlias=' + departAlias + '&departName=' + departName;
                    break;
                case 'SEC'://网络安全部
                    window.location.href = '/netsafe?departId=' + departId + '&departAlias=' + departAlias + '&departName=' + departName;
                    break;
                case 'LEVEL3'://三线
                    window.location.href = '/createThirdline?departId=' + departId + '&departAlias=' + departAlias + '&departName=' + departName;
                    break;
                default:
                    window.location.href = '/common?departId=' + departId + '&departAlias=' + departAlias + '&departName=' + departName;
                    break;
            }
        } else {
            $('#departModal').modal('hide');
            $.myAlert({title: '请注意', message: '您未选择任何部门，请重新选择'});
        }

    });
    //导航栏效果
    judgeNav();
    function judgeNav() {
        var aList = $('.navbar-header a');
        aList.each(function () {
            $(this).removeClass('nav-active');
        });
        for (var i = 0; i < aList.length; i++) {
            if (aList.eq(i).attr('href').indexOf(pathname) !== -1) {//找到
                aList.eq(i).addClass('nav-active');
                break;
            }
        }
    }


});